package com.bana.fvs.protocol;

import com.bana.fvs.model.ControllerText;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * 查询控制器基本信息
 * 开始地址，结束地址，巡检间隔时间
 */
public class SetControllerText {

    public int getId()
    {
        return 0x31;
    }

    public byte[] toBuffer(int kzqbsm,ControllerText controllerText) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeByte(0x81);
        dos.writeByte(kzqbsm);
        dos.writeByte(getId());
        dos.writeByte((byte) controllerText.getLxbh());
        if(controllerText.getWdwz()!=null)
        {
            byte[] bytes= controllerText.getWdwz().getBytes("GB2312");
            for(int i=0;i<bytes.length;++i)
            {
                dos.writeByte(bytes[i]-0xA0);
            }
        }
        dos.writeByte(0xFF);
        byte[] buffer= baos.toByteArray();
        dos.close();
        baos.close();
        return buffer;
    }
}
